void initialize(InstallInfo* inf)
{
	LOG_WATCHPOINT;

	//guardar interrupcoes iniciais
	inf->old_pic1 = get_pic1();
	inf->old_pic2 = get_pic2();
	
	//inibir interrupcoes globalmente
	Byte pic1 = 0xFF, pic2 = 0xFF;
	set_pic_var(pic1, pic2);
	
	//assinalar activacao das interrupcoes do PIC2
	//(unmask IRQ2 e IRQ9)
	unmask_pic_var(T0_IRQ, &pic1, &pic2);
	unmask_pic_var(PIC1_EN_PIC2_INTS, &pic1, &pic2);
	unmask_pic_var(PIC2_EN_PIC2_INTS, &pic1, &pic2);

	//inicializar RTC
	timer_init(2, LCOM_MODE);
	bgm_note_queue = newGQueue(10, sizeof(Note));
	se_note_queue = newGQueue(10, sizeof(Note));
	install_c_irq_handler(RTC_IRQ, rtc_isr, &(inf->old_rtc_isr));
	rtc_int_enable_periodic();
	unmask_pic_var(RTC_IRQ, &pic1, &pic2);

	//inicializar porto serie
	int serial_irq;
	if(inf->com1) { serial_irq = COM1_IRQ; com_base = COM1_ADD; }
	else { serial_irq = COM2_IRQ; com_base = COM2_ADD; }
	
	install_c_irq_handler(serial_irq, serial_isr, &(inf->old_serial_isr));
	COMConfigure();
	unmask_pic_var(serial_irq, &pic1, &pic2);

	//inicializar teclado e rato
	queueInit(&keys_queue);
	install_asm_irq_handler(KBD_IRQ, kbd_isr, &(inf->old_kbd_isr));
	unmask_pic_var(KBD_IRQ, &pic1, &pic2);

	if(inf->gfx_mode)
	{	
		//inf->has_mouse = kbc_init(1);
		inf->has_mouse = false;
		//write_kbc_data(DisableRepeat);

		if(inf->has_mouse)
		{
			mouse_queue = newGQueue(10, sizeof(MouseData));
			install_c_irq_handler(MOUSE_IRQ, mouse_isr, &(inf->old_mouse_isr));
			unmask_pic_var(MOUSE_IRQ, &pic1, &pic2);
		}

		//inicializar modo grafico
		inf->video_base = enter_graphics(inf->video_mode, &(inf->video_map));
	}

	//desinibir interrpcoes seleccionadas
	set_pic_var(pic1, pic2);

	LOG_WATCHPOINT;
}


void finalize(InstallInfo* inf)
{
	LOG_WATCHPOINT;

	//inibir interrupcoes globalmente
	set_pic_var(0xFF, 0xFF);
	
	//repor RTC
	rtc_int_disable();
	reinstall_c_irq_handler(RTC_IRQ, &(inf->old_rtc_isr));
	deleteGQueue(bgm_note_queue);
	deleteGQueue(se_note_queue);

	//repor porto serie
	int serial_irq = inf->com1 ? COM1_IRQ : COM2_IRQ;
	reinstall_c_irq_handler(serial_irq, &(inf->old_serial_isr));
	
	reinstall_asm_irq_handler(KBD_IRQ, &(inf->old_kbd_isr));
	
	//repor teclado e rato
	if(inf->gfx_mode)
	{
		if(inf->has_mouse)
		{
			reinstall_c_irq_handler(MOUSE_IRQ, &(inf->old_mouse_isr));
			deleteGQueue(mouse_queue);
		}

		//deixar modo grafico
		leave_graphics(inf->video_map);
	}

	//desinibir interrupcoes iniciais
	set_pic_var(inf->old_pic1, inf->old_pic2);

	LOG_WATCHPOINT;
}
